cmake_minimum_required(VERSION 3.15)
project(rc_demo)

# 设置C++标准为C++14
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)

# 针对不同编译器设置特定编译选项，增强跨平台兼容性
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
    # GCC编译器下添加常用的警告相关编译选项
    add_compile_options(-Wall -Wextra -pedantic)
    # 启用编译器内联警告（只有当编译器支持时才有用）
    # add_compile_options(-Winline)
endif()

# 设置优化级别，这里采用可配置的方式，默认设为-O1，用户可以通过命令行参数 -DENABLE_OPTIMIZATION=0/1 来控制是否启用优化
option(ENABLE_OPTIMIZATION "Enable compiler optimization" ON)
set(SOURCES
    ${PROJECT_SOURCE_DIR}/src/camera.cpp
    ${PROJECT_SOURCE_DIR}/src/main.cpp
)

# 创建可执行文件目标
add_executable(rc_demo ${SOURCES})

# 设置优化选项
if(ENABLE_OPTIMIZATION)
    target_compile_options(rc_demo PRIVATE -O1)
endif()

# 包含的头文件目录，使用更明确的方式指定，提高可维护性
include_directories(
    ${PROJECT_SOURCE_DIR}/external
    ${PROJECT_SOURCE_DIR}/include
    ${PROJECT_SOURCE_DIR}/common
)

# 设置安装目录相关变量，采用相对项目根目录的方式，方便调整整体安装布局
set(INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX})
set(INSTALL_LIB_DIR ${INSTALL_PREFIX}/lib)
set(INSTALL_BIN_DIR ${INSTALL_PREFIX}/bin)
set(INSTALL_INCLUDE_DIR ${INSTALL_PREFIX}/include)

# 安装可执行文件到指定的bin目录
install(TARGETS rc_demo
    RUNTIME DESTINATION ${INSTALL_BIN_DIR}
)
